<?php

declare(strict_types=1);

namespace App\Request\Web;

use Hyperf\Validation\Request\FormRequest;

class UserProfileRequest extends FormRequest
{

    public function authorize(): bool
    {
        return true;
    }

    public function rules(): array
    {
        return [
            'user.name' => [
                'sometimes',
                'required',
                'max:100'
            ],
            'user.email' => [
                'sometimes',
                'required',
                'email:rfc,dns',
                'max:255'
            ],
            'user.avatar' => [
                'sometimes',
                'required',
                'string',
            ],

            'profiles.bio' => [
                'sometimes',
                'required',
                'string',
            ],
            'profiles.website' => [
                'sometimes',
                'required',
                'string',
            ],
            'profiles.location' => [
                'sometimes',
                'required',
                'string',
            ],
            'profiles.company' => [
                'sometimes',
                'required',
                'string',
            ],
        ];
    }

    public function messages(): array
    {
        return [
            'user.email.required' => '邮箱不能为空',
            'user.email.email' => '邮箱格式不正确',
            'user.email.max' => '邮箱不能超过255个字符',

            'user.name.required' => '用户名不能为空',
            'user.name.max' => '用户名不能超过100个字符',

            'user.avatar.required' => '头像不能为空',

            'profiles.bio.required' => '个人简介不能为空',

            'profiles.website.required' => '个人网站不能为空',

            'profiles.location.required' => '所在地不能为空',

            'profiles.company.required' => '公司不能为空',
        ];
    }

    public function attributes(): array
    {
        return [
            'user.email' => '邮箱',
            'user.name' => '用户名',
            'user.avatar' => '头像',
            'profiles.bio' => '个人简介',
            'profiles.website' => '个人网站',
            'profiles.location' => '所在地',
            'profiles.company' => '公司',
        ];
    }
}
